<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-07-30 20:02:30
 * @LastEditTime: 2020-02-28 11:25:38
 * @LastEditors: Please set LastEditors
 -->
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../css/vant.css">
    <link rel="stylesheet" type="text/css" href="../css/base.css" />
    <script type="text/javascript" src="../script/vue.min.js"></script>
    <script type="text/javascript" src="../script/vant.min.js"></script>
    <script type="text/javascript" src="../script/base.js"></script>
    <script type="text/javascript" src="../script/jquery.js"></script>
    <script type="text/javascript" src="../script/ajaxFileUpload.js"></script>
    <script type="text/javascript" src="../script/layer/mobile/layer.js"></script>
    <style type="text/css">
        .content {
            display: flex;
            flex-direction: column;
            justify-content: space-between;
        }

        .mainForm {
            display: flex;
            flex-wrap: wrap;
            background-color: #fff;
        }

        .mainForm .van-field {
            width: 50%;
            display: flex;
            align-items: center;
        }

        .van-field__label {
            width: auto;
            font-weight: 600;
            font-size: 20px;
        }

        .van-field__control {
            font-weight: 600;
            font-size: 24px;
        }



        .van-cell {
            width: 50%;
        }

        .bottomBtn {
            height: 50px;
            width: 100%;
            padding: 10px 10px;
            display: flex;
        }

        .bottomBtn .van-button {
            flex: 1;
            margin: 0 10px;
        }



        .radioClass {
            font-weight: 600;
            font-size: 20px;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div class="box">
            <van-nav-bar :title="name + '明细'" id="safeTop" left-arrow @click-left="onClickLeft">
            </van-nav-bar>
            <div class="content">
                <div class="mainForm">
                    <van-field v-model="formData.ScanTime" label="扫码时间：" placeholder="自动带出扫码时间" readonly></van-field>
                    <van-field v-model="formData.JNo" label="架号：" placeholder="自动带出架号" readonly></van-field>

                    <van-field v-model="formData.ProductSpec" label="型号：" placeholder="请选择型号"
                        :readonly='shouldBindFieldClick' @click="openBaseScreen('型号') " style='width: 100%;'>
                        <template #button>
                            <van-radio-group v-model="radio" direction="horizontal" @change='groupChange'>
                                <van-radio name="1" class='radioClass'>自动</van-radio>
                                <van-radio name="2" class='radioClass'>手写</van-radio>
                            </van-radio-group>
                        </template>
                    </van-field>
                    <van-field v-model="formData.Temperature" label="水温(℃)：" placeholder="请输入水温" type='number'>

                    </van-field>
                    <van-field v-model="formData.DCTemperature" label="电池温度(℃)：" placeholder="请输入电池温度" type='number'>
                    </van-field>
                    <van-field v-model="formData.Temperature18" label="18车间循环水温度(℃)：" placeholder="请输入" type='number'>
                    </van-field>
                    <van-field v-model="formData.Temperature13" label="13车间循环水温度(℃)：" placeholder="请输入" type='number'>
                    </van-field>
                </div>
                <div class="bottomBtn">
                    <van-button type="info" @click="confirm">保 &nbsp &nbsp &nbsp &nbsp &nbsp 存
                    </van-button>
                </div>
            </div>
            <audio id="audioPlayer" preload="auto">
                <source src="../image/aigei_com.mp3" type="audio/mpeg">
            </audio>
            <div class="indexBottom">
                汇智云创 技术支持
            </div>
        </div>
    </div>

</body>

<script type="text/javascript">
    var vm;
    apiready = function () {
        var photoBrowser = api.require('photoBrowser');
        var scanTC27 = api.require('scanTC27');

        api.addEventListener({
            name: 'getCDAlarmLList'
        }, function (ret) {
            APP.getCDAlarmLList()
        })

        api.addEventListener({
            name: 'getYCKBDataLiist'
        }, function (ret) {
            APP.getYCKBDataLiist()
        })
        api.addEventListener({
            name: 'selectRow'
        }, function (ret, err) {
            console.log('ret', JSON.stringify(ret))
            if (ret.value.type == '产品') {
                vm.formData.ProductID = ret.value.row.ProductID
                vm.formData.ProductSpec = ret.value.row.name
            }
            else if (ret.value.type == '型号') {
                vm.formData.ProductID = ret.value.row.ProductID
                vm.formData.ProductSpec = ret.value.row.ProductSpec
            }
        })
        vm = new Vue({
            el: '#app',
            data: {
                timeOutObj: null,
                disabled: false,
                inputValue: '',
                shouldBindFieldClick: true,
                radio: '1',
                danwei: '℃',
                name: api.pageParam.name,
                formData: {
                    ids: '',
                    JNo: '',
                    ScanTime: '',
                    ProductSpec: '',
                    ProductID: '',
                    Temperature: '',
                    DCTemperature: '',
                    Temperature18: '',
                    Temperature13: '',
                },
                tableData: [],
            },
            created: function () {
                var that = this;
                window.localStorage.setItem('pageName', JSON.stringify(that.name))

                if (api.pageParam.ids) {
                    APP.ajax('getTempDetail', { ids: api.pageParam.ids }, function (res) {
                        console.log(JSON.stringify(res));
                        that.formData = res.ds[0]
                        that.formData.ScanTime = that.formData.ScanTime ? that.formData.ScanTime.replace('T', ' ') : ''
                    })
                }
                else {
                    console.log(JSON.stringify(api.pageParam));
                    that.formData.ids = 0
                    if (api.pageParam.obj.JNo) {
                        that.formData.JNo = api.pageParam.obj.JNo
                        that.formData.ScanTime = api.pageParam.obj.time
                        that.getgetNewestTemp()

                    }
                }
                scanTC27.registerReceiver(function (ret, err) {
                    console.log(JSON.stringify(ret));
                    var JNo = ret.barcode.split('|')[1]
                    that.formData.JNo = JNo
                    that.formData.ScanTime = APP.getFormatDate()
                    that.getgetNewestTemp()
                })


            },
            mounted() {
                APP.setSafeTop()
                APP.keyBoardChange()
            },

            methods: {
                getgetNewestTemp() {
                    var that = this;

                    APP.ajax('getNewestTemp', {}, function (res) {
                        console.log(JSON.stringify(res));

                        if (res.ds && res.ds.length >= 1) {
                            that.formData.Temperature18 = res.ds[0].Temperature18
                            that.formData.Temperature13 = res.ds[0].Temperature13
                        }
                    })
                },
                groupChange() {
                    var that = this;

                    this.shouldBindFieldClick = !this.shouldBindFieldClick
                    console.log(this.shouldBindFieldClick);
                },
                openBaseScreen: function (str) {
                    var that = this;
                    var obj;
                    if (this.shouldBindFieldClick == true) {
                        if (str == '产品') {
                            obj = {
                                allowClear: false,
                                showSearch: true,
                                searchKey: '',
                                serverSearch: false,
                                searchBy: ['name'],
                                isPaging: false,
                                type: str,
                                cmd: 'getProductList',
                                param: {}
                            }
                        }
                        else if (str == '型号') {
                            obj = {
                                allowClear: false,
                                showSearch: true,
                                searchKey: '',
                                serverSearch: false,
                                searchBy: ['JNo'],
                                isPaging: false,
                                type: str,
                                cmd: 'getProductByJNo',
                                param: {
                                    JNo: that.formData.JNo
                                }
                            }
                        }
                        api.openWin({
                            name: 'baseScreen',
                            url: 'tool/baseScreen.html',
                            reload: true,
                            slidBackEnabled: false,
                            pageParam: obj
                        })
                    }

                },
                confirm() {
                    var that = this;
                    var show = true

                    // if (that.formData.Temperature18 == null || that.formData.Temperature18 == undefined || that.formData.Temperature18 == '') {
                    //     show = false
                    //     api.confirm({
                    //         title: '提示',
                    //         msg: '请输入18车间循环水温度',
                    //         buttons: ['确定', '取消']
                    //     }, function (ret, err) {
                    //         if (ret.buttonIndex == 1) {
                    //         }
                    //     });
                    // }
                    // if (that.formData.Temperature13 == null || that.formData.Temperature13 == undefined || that.formData.Temperature13 == '') {
                    //     show = false
                    //     api.confirm({
                    //         title: '提示',
                    //         msg: '请输入13车间循环水温度',
                    //         buttons: ['确定', '取消']
                    //     }, function (ret, err) {
                    //         if (ret.buttonIndex == 1) {
                    //         }
                    //     });
                    // }

                    if (show) {
                        if (that.disabled == false) {
                            that.disabled = true
                            var obj = {
                                ids: that.formData.ids,
                                JNo: that.formData.JNo,
                                ScanTime: that.formData.ScanTime,
                                ProductSpec: that.formData.ProductSpec,
                                Temperature18: that.formData.Temperature18 ? that.formData.Temperature18 : '',
                                Temperature13: that.formData.Temperature13 ? that.formData.Temperature13 : '',
                                ProductID: that.formData.ProductID ? that.formData.ProductID : 0,
                                Temperature: that.formData.Temperature ? that.formData.Temperature : 0,
                                DCTemperature: that.formData.DCTemperature ? that.formData.DCTemperature : 0
                            }
                            console.log(JSON.stringify(obj));
                            APP.ajax('saveTemp_1', obj, function (res) {
                                // APP.ajax('saveTemp', obj, function (res) {
                                that.disabled = false
                                api.toast({
                                    msg: '提交成功！'
                                })
                                api.sendEvent({
                                    name: 'refreshWatertemperatureList'
                                })
                                setTimeout(() => {
                                    api.closeWin();
                                }, 1000);
                            })
                        }

                    }

                },
                onClickLeft() {
                    var that = this
                    api.sendEvent({
                        name: 'refreshWatertemperatureList'
                    })
                    api.closeWin()
                },
            }
        })
    };
</script>

</html>